<template>
    <h2>用户赎回投资</h2>

    <table class="table table-bordered">
       <tr>
            <td>投资项目名称</td>
            <td>{{ state.I_Name }}</td>
       </tr>
       <tr>
            <td>总额度</td>
            <td>{{ state.I_Sum }}</td>
       </tr>
       <tr>
            <td>已投金额</td>
            <td>
              {{ state.I_Money }}
            </td>
       </tr>
       <tr>
            <td>赎回金额</td>
            <td><input type="text" v-model="UR_Money" />CNY</td>
       </tr>
       <tr>
            <td></td>
            <td><input type="button" value="赎回" @click="redeem" /></td>
       </tr>
    </table>

</template>

<script setup lang="ts">
import {ref, reactive, onMounted,toRefs} from 'vue'
import {useRouter,useRoute} from 'vue-router'
import {useStore} from '../../store/user'
const useStores=useStore();
import axios from 'axios';
const router=useRouter();
const route=useRoute();
const data:any=reactive({
    state:{
       
    },
    ListCount:'',
    PageCount:'',
    UR_Money:'',
    list:[],
    llist:[]
})
let {state,list,ListCount,PageCount,llist,UR_Money} =toRefs(data);
onMounted(()=>{
  show();
})

//8.	管理员-理财列表分页展示
const show=()=>{
    axios({
        url:"/api/Invest/SelById",
        method:'get',
        params:{
            iid:route.query.id
        }
    })
    .then(res=>{
        console.log(res);
        state.value=res.data.data[0];
    })
}

//5.	请按照课程完成用户完成撤回功能（5分）
const redeem=()=>{
    
    axios({
        url:"/api/Invest/AddRedeem",
        method:'post',
        data:{
            U_Id:useStores.userInfo.U_Id,
            UI_Id:route.query.id,
            UR_Money:UR_Money.value
           
        }
    })
    .then(res=>{
        console.log(res);
        if(res.data.data>0)
        {
            alert("赎回成功");
            router.push('/userInvestList');
        }
        else
        {
            alert("赎回失败");
            return;
        }
    })
}
</script>


<style>


</style>